<template>
	<view class="container">
		<view class="category-list">
			<scroll-view scroll-x :show-scrollbar="false" class="scroll-box">
				<view class="cate-item" v-for="(v,i) in 10" :key="i" :class="{'actived': categoryId === i}"
					@click="changeCategoryItem(i)">
					<image src="/static/shop/category.jpeg" mode="aspectFill" class="cate-img"></image>
					<view class="cate-name">网袋</view>
				</view>
			</scroll-view>
		</view>

		<view class="sort-type f-c-between">
			<view class="sort-item" v-for="(item,i) in sortList" :key="item.value"
				:class="{'text-center':i==1,'f-a-center f-j-end':(i+1)==sortList.length,'actived':params.sortType==item.value}"
				@click="changeSortType(item.value)">
				{{item.label}}
				<view v-if="item.value=='price'" class="sort flex">
					<span class="iconfont icon-paixujiantoushang"
						:style="{'color':params.priceSort=='ascend'?'#FFAA29':'#8A8A8A'}"></span>
					<span class="iconfont icon-paixujiantouxia"
						:style="{'color':params.priceSort=='descend'?'#FFAA29':'#8A8A8A'}"></span>
				</view>
			</view>
		</view>

		<view class="product-list f-c-between">
			<view class="product-item" v-for="(v,i) in 9" :key="i" @click="goDetail(i)">
				<image src="/static/shop/category.jpeg" mode="aspectFill" class="item-img"></image>
				<view class="item-info">
					<view class="ellipsis2 info-name">明治meiji 雪吻巧克力 草莓口味</view>
					<view class="info-price f-j-between f-a-end">
						<view class="price">78.00</view>
						<view class="payed">1235人已付款</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore line :status="loadStatus" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				categoryId: 0,
				sortList: [{
						label: '综合',
						value: 'all'
					},
					{
						label: '销量',
						value: 'sale'
					},
					{
						label: '价格',
						value: 'price',
					}
				],
				params: {
					currentPage: 1,
					pageSize: 20,
					sortType: 'all',
					priceSort: '', //ascend升序，descend降序
				},
				productList: []
			}
		},
		computed: {
			loadStatus() {
				if (this.productList.length == 0) return ""
				if (this.productList.length < this.params.total) return 'loadmore'
				if (this.productList.length == this.params.total) return "nomore"
			}
		},
		methods: {
			//切换分类
			changeCategoryItem(id) {
				this.categoryId = id
			},

			//切换排序类型
			changeSortType(type) {
				let _type = type
				if (_type == 'price') {
					if (this.params.priceSort == '' || this.params.priceSort == 'descend') {
						this.params.priceSort = 'ascend'
					} else {
						this.params.priceSort = 'descend'
					}
				}
				this.params.sortType = _type
			},

			//获取商品列表
			getProductList() {

			},

			//跳转商品详情
			goDetail(id) {
				uni.navigateTo({
					url: '/pages/shop/detail?id=' + id
				})
			}
		},
		onReachBottom() {
			if (this.productList.length == this.params.total) {
				return
			}
			this.params.currentPage++
			this.getProductList()
		}
	}
</script>

<style>
	page {
		background-color: #F4F5F7;
	}
</style>
<style scoped lang="scss">
	.category-list {
		padding: 20rpx 0 12rpx 30rpx;
		background-color: #ffffff;
		border-bottom: 1px solid #c1c1c1;

		.scroll-box {
			white-space: nowrap;
		}

		.cate-item {
			width: 140rpx;
			text-align: center;
			margin-right: 24rpx;
			display: inline-block;

			.cate-img {
				width: 140rpx;
				height: 140rpx;
				border-radius: 12rpx;
				display: block;
			}

			.cate-name {
				width: 100%;
				font-weight: 400;
				font-size: 28rpx;
				color: #3C3832;
				margin-top: 8rpx;
			}

			&.actived {
				.cate-img {
					width: 132rpx;
					height: 132rpx;
					border: 4rpx solid #FFAA29;
				}

				.cate-name {
					color: #FFAA29;
					font-weight: 500;
				}
			}
		}
	}

	.sort-type {
		height: 70rpx;
		padding: 0 64rpx;
		background-color: #ffffff;

		.sort-item {
			width: 33.3%;
			font-weight: 400;
			font-size: 26rpx;
			color: #8A8A8A;

			&.actived {
				color: #FFC046;
			}

			.sort {
				margin-left: 4rpx;
				flex-direction: column;

				.iconfont {
					font-size: 28rpx;
				}

				.icon-paixujiantoushang {
					margin-bottom: -12rpx;
				}

				.icon-paixujiantouxia {
					margin-top: -12rpx;
				}
			}
		}
	}

	.product-list {
		padding: 20rpx 24rpx;
		flex-wrap: wrap;

		.product-item {
			width: 344rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 19rpx 0px rgba(0, 0, 0, 0.11), 0px 0px 19rpx 0px rgba(0, 0, 0, 0.11);
			border-radius: 8rpx;
			margin-bottom: 18rpx;

			.item-img {
				width: 344rpx;
				height: 344rpx;
				display: block;
				border-radius: 8rpx 8rpx 0 0;
			}

			.item-info {
				padding: 10rpx 20rpx;

				border-radius: 0 0 8rpx 8rpx;

				.info-name {
					font-weight: 400;
					font-size: 24rpx;
					color: #333333;
				}

				.info-price {
					margin-top: 2rpx;

					.price {
						font-weight: 500;
						font-size: 30rpx;
						color: #FF691B;
						position: relative;

						&:before {
							content: '¥';
							font-size: 20rpx;
						}
					}

					.payed {
						font-weight: 400;
						font-size: 20rpx;
						color: #7C7C7C;
					}
				}
			}
		}
	}
</style>